package org.javason.jsonrpc;

import java.util.Locale;

import net.sf.json.JSONObject;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.BeanNameViewResolver;

public class AbstractJsonRpcTestCase extends org.javason.test.AbstractJsonRpcTestCase {

	public void testTrue() { assertTrue(true); }
	
	public JSONObject callMethod(Object serviceBean, String methodName, Object ... params) 
			throws Exception {
		
		JSONObject req = JsonRpcRequestFactory.createJsonRpcRequest(methodName, params);
		JsonRpcServiceExporter exporter = new JsonRpcServiceExporter();
		exporter.setServiceBean(serviceBean);
		return makeRequest(exporter, req);
	}
	
	
	public JSONObject callMethod(Object serviceBean, 
				  String methodName, 
				  JSONObject params) throws Exception {
		
		JsonRpcServiceExporter exporter = new JsonRpcServiceExporter();
		exporter.setServiceBean(serviceBean);
		JSONObject req = JsonRpcRequestFactory.createJsonRpcRequest(0, methodName, params);	
		return makeRequest(exporter, req);
	}
	
	protected void renderModelAndView(ModelAndView mv, 
			  MockHttpServletRequest request, 
			  MockHttpServletResponse response) throws Exception {

		JsonRpcServiceView view = new JsonRpcServiceView();
		assertNotNull(view);
		view.render(mv.getModel(), request, response);
		
		System.out.println("Status: " + response.getStatus());
		System.out.println(response.getContentAsString());
	}
	
	protected void setUp() { }
	
	@Override
	protected String[] getLocations() {
		// TODO Auto-generated method stub
		return null;
	}
	
}
